from sklearn import preprocessing
import numpy as np
# from scipy.sparse import csr_matrix
enc = preprocessing.OneHotEncoder()
productData = np.array([[0, 0, 3], [1, 1, 0], [2, 2, 1], [1, 0, 2], [0, 1, 2]])
enc.fit(productData)
Ohe = enc.transform(productData)
# print Ohe.__dict__
# print Ohe.indptr
# print Ohe.indices
# print Ohe.data
# print Ohe
print (Ohe.toarray())   #结果参考P29页例子说明。

#-----------------csr_matrix--------------------------#
# indptr = np.array([0, 3, 6])
# indices = np.array([0, 1, 2, 0, 1, 2])
# data = np.array([1, 2, 3, 4, 5, 6])
# print csr_matrix((data, indices, indptr)).toarray()
